package NetAPI;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {
    public static void main(String[] args) {
        try {
            // File file = new File("hello.txt");
            InetAddress inet1 = InetAddress.getByName("192.168.10.14");
            System.out.println("inet1 = " + inet1);
            InetAddress inet2 = InetAddress.getByName("www.atguigu.com");
            System.out.println("inet2 = " + inet2);
            InetAddress inet3 = InetAddress.getByName("127.0.0.1");
            System.out.println("inet3 = " + inet3);
            // 获取本地 ip
            InetAddress inet4 = InetAddress.getLocalHost();
            System.out.println("Local IP: " + inet4);
            // getHostName()
            System.out.println("inet2.getHostName() = " + inet2.getHostName());
            // getHostAddress()
            System.out.println("inet2.getHostAddress() = " + inet2.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
